function tick(id,createTime,second) {
    var today;
    var txt = "";
    var timeout = second;
    today = formatDate(new Date());
    var strDate2 = createTime;
    today = Date.parse(today.replace(/-/g, "/ "));
    strDate2 = Date.parse(strDate2.replace(/-/g, "/ "));
    var maxtime = timeout - (today - strDate2) / (1000);
    if (maxtime >= 0) {
        minutes = Math.floor(maxtime / 60);
        seconds = Math.floor(maxtime % 60);
        if (parseInt(minutes, 10) < 10) {
            minutes = '0' + minutes;
        }
        if (parseInt(seconds, 10) < 10) {
            seconds = '0' + seconds;
        }
        txt = minutes + ":" + seconds;
        $("#timer-count-"+id).html(txt);
    } else {
        clearInterval(tick1);
        $("#pay-btn-"+id).addClass("disable");
        $("#pay-btn-"+id).hide();
    }
}

//弹出提示 取消订单
var ipromptCancel = {
    //tips:提示
    //sureBtn:确认按钮，类型对象，如{label:"确定"，func:function(){}}
    //cancelBtn:取消按钮，类型对象，如{label:"取 消"，func:function(){}}
    show: function(tips, sureBtn, cancelBtn) {
        $prompt = this;
        $(".mask").show();
        $(".mask").click(function() {
            $prompt.hide();
        });
        $(".prompt>.prompt-tips").html(tips);
        $(".prompt-btn>.sure-btn").html(sureBtn.label ? sureBtn.label: "取消订单");
        $(".prompt-btn>.cancel-btn").html(cancelBtn.label ? cancelBtn.label: "返 回");
        $(".prompt").show();
        $(".prompt-btn>.sure-btn").bind("click",
            function() {
                $prompt.hide();
                if (sureBtn.func) {
                    sureBtn.func();
                }
            });
        $(".prompt-btn>.cancel-btn").bind("click",
            function() {
                $prompt.hide();
                if (cancelBtn.func) {
                    cancelBtn.func();
                }
            });
    },
    hide: function() {
        $(".mask").hide();
        $(".prompt").hide();
        $(".prompt>.prompt-tips").html("");
        $(".prompt-btn>.sure-btn").html("");
        $(".prompt-btn>.cancel-btn").html("");
        $(".prompt-btn>.sure-btn").unbind("click");
        $(".prompt-btn>.cancel-btn").unbind("click");
    }

};

//弹出提示
var iprompt = {
    //tips:提示
    //sureBtn:确认按钮，类型对象，如{label:"确定"，func:function(){}}
    //cancelBtn:取消按钮，类型对象，如{label:"取 消"，func:function(){}}
    show: function(tips, sureBtn, cancelBtn) {
        $prompt = this;
        $(".mask").show();
        $(".mask").click(function() {
            $prompt.hide();
        });
        $(".prompt>.prompt-tips").html(tips);
        $(".prompt-btn>.sure-btn").html(sureBtn.label ? sureBtn.label: "确 定");
        $(".prompt-btn>.cancel-btn").html(cancelBtn.label ? cancelBtn.label: "取 消");
        $(".prompt").show();
        $(".prompt-btn>.sure-btn").bind("click",
            function() {
                $prompt.hide();
                if (sureBtn.func) {
                    sureBtn.func();
                }
            });
        $(".prompt-btn>.cancel-btn").bind("click",
            function() {
                $prompt.hide();
                if (cancelBtn.func) {
                    cancelBtn.func();
                }
            });
    },
    hide: function() {
        $(".mask").hide();
        $(".prompt").hide();
        $(".prompt>.prompt-tips").html("");
        $(".prompt-btn>.sure-btn").html("");
        $(".prompt-btn>.cancel-btn").html("");
        $(".prompt-btn>.sure-btn").unbind("click");
        $(".prompt-btn>.cancel-btn").unbind("click");
    }
};

function cancelBtn(orderId, state) {
    var txt = "订单取消后不可恢复，确定取消？";
    if (state == 1) {
        txt = "订单取消后不可恢复，退款进度请查看【订单详情】，确定取消？";
    }
    ipromptCancel.show(txt, {
            func: function() {
                goAction('/me/cancel-orderForm.do', {
                        id: orderId
                    },
                    'text',
                    function(result) {
                        if (result == '40000') {
                            location.reload();
                        }
                        if (result == '50000') {
                            cancelFail();
                        }
                    });
            }
        },
        {});
}

function cancelFail() {
    tips.show("订单取消失败,仍需取消订单请联系客服", {
            label: "知道了",
            func: function() {
                location.reload();
            }
        },
        true, true);
}

function sureBtn(orderId) {
    iprompt.show("确定收货吗？", {
            func: function() {
                goAction('/me/sure-orderForm.do', {
                        id: orderId
                    },
                    'text',
                    function(result) {
                        if (result == '40000') {
                            location.reload();
                        }
                    });
            }
        },
        {});
}

function myOrder(state) {
    location.href = "/wx/my-order.do?state=" + state;
}

function payBtn(orderId) {
    if ($("#pay-btn-" + orderId).hasClass("disable")) {
        return;
    }
    location.href = "/payBefore/index.do?orderId=" + orderId;
}

function orderDetail(orderId) {
    location.href = "/wx/order-detail.do?orderId=" + orderId;
}

//去逛逛
function goIndex() {
    location.href = "/wx/index.do?t=" + new Date().getTime();
}